/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import entity.Category;
import entity.News;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.CategoryModel;
import model.NewsModel;

/**
 * 
 * @author xuanhung2401
 */
@SuppressWarnings("serial")
public class NewsCategory extends HttpServlet {

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		String url = request.getRequestURI();
		String[] splitUrl = url.split("/");
		String cateAlias = splitUrl[splitUrl.length - 1];
		NewsModel newsModel = new NewsModel();
		CategoryModel cateModel = new CategoryModel();
		Category cate = cateModel.findByAlias(cateAlias);
		if (cate != null && !cate.getAlias().equalsIgnoreCase("")) {
			for (String string : cate.getSubCategory()) {
				List<News> listSub = newsModel.findBySubCategory(
						cate.getAlias(), string, 6);
				request.setAttribute("list" + string, listSub);
			}
			request.setAttribute("cate", cate);
			request.getRequestDispatcher("/cate_detail.jsp").forward(request,
					response);
		} else {
		}
	}
}
